package tagdb.model;

import tagdb.algorithm.match.PeptideSpectrumMatch;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

/**
 * <b>PeptideHit</b>
 * <p>
 * This class represents a peptide hit.
 * </p>
 *
 * @author T.Muth
 */
public class PeptideHit {

    /**
     * The peptide sequence.
     */
    private String sequence;

    /**
     * The start of the peptide sequence in the protein.
     */
    private int start;

    /**
     * The end of the peptide sequence in the protein.
     */
    private int end;

    /**
     * The peptide spectrum match for this peptide hit.
     */
    private TreeMap<String, PeptideSpectrumMatch> spectrumMatches;

    /**
     * PeptideHit constructor, taking the sequence as only parameter.
     *
     * @param sequence      The String sequence.
     * @param psm The peptide spectrum match
     */
    public PeptideHit(String sequence, PeptideSpectrumMatch psm) {
        this.sequence = sequence;
        this.spectrumMatches = new TreeMap<String, PeptideSpectrumMatch>();
        this.spectrumMatches.put(psm.getSpectrumTitle(), psm);
        // TODO: implement start + end position feature
        // this.start = start;
        // this.end = end;
    }

    /**
     * Returns the peptide sequence.
     *
     * @return the sequence
     */
    public String getSequence() {
        return sequence;
    }

    /**
     * Sets the peptide sequence
     *
     * @param sequence the peptide sequence
     */
    public void setSequence(String sequence) {
        this.sequence = sequence;
    }

    /**
     * Convenience method to retrieve a unique PSM.
     *
     * @return The list of PSMs.
     */
    public PeptideSpectrumMatch getSingleSpectrumMatch() {
        return spectrumMatches.firstEntry().getValue();
    }

    /**
     * Returns the spectrum matches as tree map.
     *
     * @return The spectrum matches.
     */
    public TreeMap<String, PeptideSpectrumMatch> getSpectrumMatches() {
        return spectrumMatches;
    }

    /**
     * Returns the spectrum matches as list.
     * @return The spectrum matches list.
     */
    public List<PeptideSpectrumMatch> getSpectrumMatchesList() {
        return new ArrayList<PeptideSpectrumMatch>(spectrumMatches.values());
    }

    /**
     * Sets the spectrum matches.
     *
     * @param spectrumMatches The spectrum matches to set.
     */
    public void setSpectrumMatches(TreeMap<String, PeptideSpectrumMatch> spectrumMatches) {
        this.spectrumMatches = spectrumMatches;
    }

    /**
     * Returns the peptide start position.
     *
     * @return the peptide start position.
     */
    public int getStart() {
        return start;
    }

    /**
     * Returns the peptide end.
     *
     * @return the end
     */
    public int getEnd() {
        return end;
    }

    /**
     * Sets the start position of the peptide.
     *
     * @param start The start position of the peptide.
     */
    public void setStart(int start) {
        this.start = start;
    }

    /**
     * Sets the end position of the peptide.
     *
     * @param end The end position of the peptide.
     */
    public void setEnd(int end) {
        this.end = end;
    }

}
